import Vue from 'vue'
import Router from 'vue-router'
import { component } from 'vue/types/umd'

Vue.use(Router)

// path: 'table',
// name: 'Table',
// component: () => import('@/views/table/index'),
// meta: { title: 'Table', icon: 'table' }

const routes = [
    {
        path: 'home',
        name: 'Home',
        component: () => import('@/views/home/Home.vue'),
        meta: { title: '首页', icon: 'table' }
    },
    {
        path: 'login',
        name: 'login',
        component: () => import('@/views/login/Login.vue'),
        meta: { title: '登录' ,icon: 'table'}
    }
]

const router = new Router({
    routes: routes
})
console.log(router)
router.beforeEach((to,from,next)=>{
    console.log(to)
    if(localStorage.getItem('token')|| to.name=="Login"){
        next()
    }else{
        next({
            path: 'login'
        })
    }
    next()
})

export default router